package javolution.util;

import java.util.Iterator;
import java.util.NoSuchElementException;
import javolution.context.ObjectFactory;
import javolution.util.FastCollection;

/* loaded from: classes2.dex */
final class FastIterator implements Iterator {
    private static final ObjectFactory FACTORY = new ObjectFactory() { // from class: javolution.util.FastIterator.1
        /* JADX INFO: Access modifiers changed from: protected */
        @Override // javolution.context.ObjectFactory
        public void cleanup(Object obj) {
            FastIterator fastIterator = (FastIterator) obj;
            fastIterator._collection = null;
            fastIterator._current = null;
            fastIterator._next = null;
            fastIterator._tail = null;
        }

        /* JADX INFO: Access modifiers changed from: protected */
        @Override // javolution.context.ObjectFactory
        public Object create() {
            return new FastIterator();
        }
    };
    private FastCollection _collection;
    private FastCollection.Record _current;
    private FastCollection.Record _next;
    private FastCollection.Record _tail;

    private FastIterator() {
    }

    public static FastIterator valueOf(FastCollection fastCollection) {
        FastIterator fastIterator = (FastIterator) FACTORY.object();
        fastIterator._collection = fastCollection;
        fastIterator._next = fastCollection.head().getNext();
        fastIterator._tail = fastCollection.tail();
        return fastIterator;
    }

    @Override // java.util.Iterator
    public boolean hasNext() {
        return this._next != this._tail;
    }

    @Override // java.util.Iterator
    public Object next() {
        FastCollection.Record record = this._next;
        if (record != this._tail) {
            this._current = record;
            this._next = record.getNext();
            return this._collection.valueOf(this._current);
        }
        throw new NoSuchElementException();
    }

    @Override // java.util.Iterator
    public void remove() {
        FastCollection.Record record = this._current;
        if (record == null) {
            throw new IllegalStateException();
        }
        FastCollection.Record previous = record.getPrevious();
        this._collection.delete(this._current);
        this._current = null;
        this._next = previous.getNext();
    }
}
